package com.wangyu.generator.core.impl;

import com.google.common.collect.Lists;
import com.wangyu.generator.config.CodeConfigType;
import com.wangyu.generator.core.connect.Connector;
import com.wangyu.generator.core.context.CodeContext;
import com.wangyu.generator.core.context.GeneratorType;
import com.wangyu.generator.core.utils.GeneratorStringUtils;
import java.util.List;
import java.util.Map;
import org.apache.velocity.VelocityContext;

/**
 * JSP生成器
 *
 * @author: zhangQ
 * @date: 2016-8-18 17:07
 */
public class JspGenerator extends AbstractGeneratorImpl {

  @Override
  public void initVelocityContext(VelocityContext velocityContext, CodeContext cxt) {
    super.initVelocityContext(velocityContext, cxt);

    // 获取所有的属性
    String tableName = cxt.getTableName();
    Connector connector = (Connector) cxt.getAttribute(CodeConfigType.JDBC_CONNECTOR);
    Map<String, String> columnNameTypeMap = connector.getColumnNameType(tableName);

    List<String> fields = Lists.newArrayList();
    for (String col : columnNameTypeMap.keySet()) {
      String field = GeneratorStringUtils.format(col);
      fields.add(field);
    }
    velocityContext.put(CodeConfigType.FIELDS.getDesc(), fields);
  }

  @Override
  protected GeneratorType getPackageConfigType() {
    return GeneratorType.JSP;
  }

  @Override
  protected String getDescription() {
    return "";
  }
}
